package dukeAll;

public class RatRoute {
	  String[] map;
	 
	  public int findRoute (int x, int y, int x_end, int y_end) {
	    if(x == x_end && y == y_end)
	      return 1;
	    if(map[y].charAt(x) == 'X')
	      return 0;
	      
		int count = 0;

	    if(x < x_end)
	      count += findRoute(x+1, y, x_end, y_end);
	    if(x > x_end)
	      count += findRoute(x-1, y, x_end, y_end);
	    if(y < y_end)
	      count += findRoute(x, y+1, x_end, y_end);
	    if(y > y_end)
	      count += findRoute(x, y-1, x_end, y_end);



	    return count;


	  }

	  public int numRoutes(String[] enc) {
	    map = enc;
	    int x = 0, y = 0, x_end = 0, y_end = 0;
	    
	    for(int i = 0; i < map.length; i++){
	      for(int j = 0; j < map[0].length(); j++) {
	        if (map[i].charAt(j) == 'R') {
	         x = j;
	         y = i;
	        }
	        else if (map[i].charAt(j) == 'C') {
	         x_end = j;
	         y_end = i;
	        }
	      }
	    }
	    return findRoute(x, y, x_end, y_end);
	  }
	}